package com.geping.etl.config;


import com.geping.etl.utils.EnvUitl;
import com.google.common.base.Predicates;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;

import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2 // 启用 Swagger
@EnableWebMvc
public class SwaggerConfig{

    @Bean
    public Docket createRestApi() {
        boolean enable = "on".equals(EnvUitl.props.getProperty("swagger.enable"))?true:false;
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(enable)
                .apiInfo(apiInfo())
                .select()
                // 为当前包路径
                .apis(Predicates.or(RequestHandlerSelectors.basePackage("com.geping.etl.common.controller")))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建 api 文档的详细信息函数，注意这里的注解引用的是哪个
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 页面标题
                .title("USERS_CORE Application Swagger2 RESTFul API")
                // 创建人
                .contact(new Contact("jiangfeng.zhu", "", "zhujiangfeng@swordgate.cn"))
                // 版本号
                .version("1.0")
                // 描述
                .description("USERS_CORE API doc")
                .build();
    }
}
